package com.ht.medicaltreatment.activity

import android.content.Intent
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.adapter.BloodCollectionRecordAdaptger
import com.ht.medicaltreatment.bean.PatientFormBean
import com.ht.medicaltreatment.viewmodel.BloodOrderListViewModel
import kotlinx.android.synthetic.main.activity_collection_record_layout.recyclerView

class BloodCollectionRecordActivity:BaseActivity(), OnItemClickListener {

    private val model by viewModels<BloodOrderListViewModel>()
    private var id = -1
    private lateinit var adapter: BloodCollectionRecordAdaptger

    override fun getLayoutId() = R.layout.activity_collection_record_layout

    override fun init() {
        setTitle("采样计划列表")
        id = intent.getIntExtra("patientId",-1)
        recyclerView.layoutManager = LinearLayoutManager(this)
        adapter = BloodCollectionRecordAdaptger()
        recyclerView.adapter = adapter
        adapter.setOnItemClickListener(this)

    }

    override fun onResume() {
        super.onResume()
        showProgress()
        model.orderList("$id"){
            dismissProgress()
            adapter.setNewInstance(it)
        }
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val item = adapter.getItem(position) as PatientFormBean
        val intent = Intent(this,BloodCollectionFormRecordActivity::class.java)
        intent.putExtra("uid",item.id)
        startActivity(intent)
    }
}